package edu.hunau.cxb19.oop.class21;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.Test;

/**
 *
 * @author hb
 *
 *         2020-03-24 15:08:42
 */
public class ChangeTypeTest {

	@Test
	public void toArray() {
		List<String> list = new ArrayList<String>();
		Collections.addAll(list, "abc", "123", "456");

		Object[] objs = list.toArray();
		String[] strs = list.toArray(new String[0]);
		System.out.println(Arrays.toString(strs));
	}

	@Test
	public void toList() {
		String[] strs = new String[] { "abc", "123", "456" };
		List<String> listArray = Arrays.asList(strs);
		System.out.println(listArray.get(0));
		System.out.println(listArray.set(0, "000"));
		System.out.println(listArray.add("123"));//运行时抛出异常。当前的List长度不可变
		//将长度固定的集合转成具有完全功能的List集合
		List<String> list=new ArrayList<>(listArray);
	}
}
